package com.transino.bop.utils;

import javax.servlet.http.HttpServletRequest;

public class SqlExecutorUtil {
	
	private static SqlExecutorUtil instance = null;
	
	public SqlExecutorUtil() {}
	
	public static SqlExecutorUtil getInstance() {
		if(instance==null) instance = new SqlExecutorUtil();
		return instance;
	}
	
	public String getInsertSql(String table, HttpServletRequest request) {
		StringBuilder front = new StringBuilder("insert into " + table + " (id,");
		StringBuilder backend = new StringBuilder(" values (:id,");
		for(Object key:request.getParameterMap().keySet()) {
			front.append(" " + key.toString() + ",");
			backend.append(" :" + key.toString() + ",");
		}
		return front.toString().substring(0, front.toString().length()-1) + ")" +
					backend.toString().substring(0, backend.toString().length()-1) + ")";
	}

}
